/**
 * @description mongose 连接数据库
 * @author liyunfu
 */

const mongoose = require('mongoose')

// const url = 'mongodb://localhost:10050' //本地mongodb地址
const url = 'mongodb://47.101.203.177:10050' //本地mongodb地址

const dbName = 'testdb'  //数据库名

//开始连接
mongoose.connect(`${url}/${dbName}`, {
  useNewUrlParser: true,
  useUnifiedTopology: true
})

//连接对象
const db = mongoose.connection

db.on('error', err => {
  console.error('mongoose connect error', err)
})
db.once('open',()=>{
  console.log('mongoose 连接成功');
})
module.exports = mongoose